﻿using System;

namespace CSEngine
{
    public struct Move
    {
        public HexDigit x, y;

        public Move(HexDigit xcoord, HexDigit ycoord)
        {
            x = xcoord;
            y = ycoord;
        }

        public override string ToString()
        {
            return ("" + x + y);
        }

        public static Move Parse(string s)
        {
            HexDigit x, y;

            s = s.Trim();
            if (!HexDigit.TryParse(s.Substring(0, 1), out x) || !HexDigit.TryParse(s.Substring(1).Trim(), out y))
                throw new ArgumentException();

            else return new Move(x, y);
        }

        public static bool TryParse(string s, out Move m)
        {
            try
            {
                m = Parse(s);
                return true;
            }
            catch (ArgumentException)
            {
                m = new Move();
                return false;
            }
        }
    }
}
